import FrameAnimation from "./FrameAnimation";

export default class SelfAnimation extends cc.Node {


    protected animation:FrameAnimation;


    constructor(){
        super();
    }

    getAnimation(){
        return this.animation;
    }

    init(name:string,atlas:cc.SpriteAtlas,startFrame:number,endFrame:number,autoPlayer:boolean = false){
        if(!this.animation){
            this.animation = this.addComponent(FrameAnimation)
            this.animation.setAtlas(atlas)
            this.animation.setActionName(name)
            this.animation.setStartFrame(startFrame)
            this.animation.setEndFrame(endFrame)
            this.animation.setAutoPlay(autoPlayer)
            this.animation.init(); 
        }
    }

    play(name:string,count:number = -1){
        this.animation.play(name,count)
    }

    setFinishCallback(func:(actionName: string)=>void ){
        this.animation.setFinishCallback(func)
    }

}
